import subprocess

popen = subprocess.Popen(['netstat','-afq'],stdin = subprocess.PIPE,stdout= subprocess.PIPE,shell=True,bufsize=0)

# try:
while True:
    line = popen.stdout.readline()
    line_2 = line.decode("gbk")
    link = line_2.split(" ")
    print(line_2)
    if(popen.poll() is not None):
        break

# except:
#     print("IO ERROR")